package com.tlgen.orm.controller;

import com.tlgen.orm.common.BaseEntity;
import com.tlgen.orm.common.PageResult;
import com.tlgen.orm.domain.SysUser;
import com.tlgen.orm.common.Model;
import com.tlgen.orm.factory.QueryOperator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class SysUserController {

    @GetMapping("/select")
    public List<SysUser> select() {
        return Model.selectAll(SysUser.class);
    }

    @GetMapping("/selectOne")
    public SysUser selectOne() {
        SysUser user = new SysUser();
        user.setGender(1);
        return Model.selectOne(user, new QueryOperator<SysUser>()
                .like(SysUser::getMobile, "136")
                .orderByDesc(BaseEntity::getCreateTime));
    }

    @GetMapping("/selectPage")
    public PageResult<SysUser> selectPage() {
        return Model.selectPage(1, 3, new QueryOperator<SysUser>()
                .like("username", "小"), SysUser.class);
    }

}
